﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class Department_U : FormBase1
    {
        public delegate void DoAction();//如果有参数的话，定义参数 

        public DoAction FatherRefresh;
        private SVC.client.Depratment dm = null;
        public Department_U(SVC.client.Depratment _dm)
        {
            InitializeComponent();
            dm = _dm;
        }

        private void btn_new_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            valildbefore();
            if (dxValidationProvider1.Validate())
            {
                SVC.client.Depratment fz = new SVC.client.Depratment();
                dm.DepCode = te_did.Text;
                fz.DepName = te_name.Text;
                fz.shopcode = lue_shop.EditValue.ToString();
                fz.phone = te_phone.Text;
                fz.leader = te_legalrep.Text;
                string result = my.bw.Depratment_Update(dm, my.ACID);
                if(string.IsNullOrWhiteSpace(result))
                {
                    FatherRefresh();
                    this.Close();
                }
                else
                {
                    Comm.ShowErorr(result);
                }
            }
        }

        private void valildbefore()
        {
            te_did.Text = te_did.Text.Trim();
            te_name.Text = te_name.Text.Trim();
            te_phone.Text = te_phone.Text.Trim();
            te_legalrep.Text = te_legalrep.Text.Trim();
        }


        private void load()
        {
            te_did.Text = dm.DepCode;
            te_name.Text = dm.DepName;
            te_phone.Text = dm.phone;
            te_legalrep.Text = dm.leader;
            lue_shop.EditValue = dm.shopcode;
        }

        private void Department_U_Load(object sender, EventArgs e)
        {
            lue_shop.Properties.DataSource = my.bw.shop_Get("shopcode", my.ACID) ;
            load();
        }

    }
}